﻿namespace ClearLines.Bumblebee

open System

module Array =

    let shuffle (rng: Random) items =
        let rec shuffleTo (indexes: int[]) upTo =
            match upTo with
            | 0 -> indexes
            | _ ->
                let fst = rng.Next(upTo)
                let temp = indexes.[fst]
                indexes.[fst] <- indexes.[upTo] 
                indexes.[upTo] <- temp
                shuffleTo indexes (upTo - 1)
        let length = Array.length items
        let indexes = [| 0 .. length - 1 |]
        let shuffled = shuffleTo indexes (length-1)
        Array.permute (fun i -> shuffled.[i]) items
